package com.wj.facedetect.activity.home;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.wj.facedetect.R;
import com.wj.facedetect.activity.base.BaseActivity;
import com.wj.facedetect.bean.home.RefactorBean;
import com.wj.facedetect.net.ReqUrls;
import com.wj.facedetect.util.CommonUtils;
import com.wj.facedetect.util.PreferencesUtils;

import java.math.BigDecimal;

/**
 * Created by tangkun on 2018/4/3.
 */

public class FaceCheckDetailActivity extends BaseActivity {
    public static final String TAG = FaceCheckDetailActivity.class.getName();
    private SimpleDraweeView simpleDraweeViewhead1, simpleDraweeViewhead2, simpleDraweeViewCjz1, simpleDraweeViewCjz2;
    private TextView tvSim, tvName, tvIdCardNo, tvKuName;
    private TextView tvLeft;
    private RefactorBean refactorBean;
    private int refactorPos;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_face_check_detail);
        refactorBean = (RefactorBean) getIntent().getSerializableExtra("refactorBean");
        refactorPos = getIntent().getIntExtra("position", 0);
        initView();
    }

    private void initView() {
        simpleDraweeViewhead1 = (SimpleDraweeView) findViewById(R.id.iv_head_1);
        simpleDraweeViewhead2 = (SimpleDraweeView) findViewById(R.id.iv_head_2);
        simpleDraweeViewCjz1 = (SimpleDraweeView) findViewById(R.id.iv_head_cjz_1);
        simpleDraweeViewCjz2 = (SimpleDraweeView) findViewById(R.id.iv_head_cjz_2);
        tvSim = (TextView) findViewById(R.id.tv_sim);
        tvName = (TextView) findViewById(R.id.tv_kzp_name);
        tvIdCardNo = (TextView) findViewById(R.id.tv_idcard);
        tvKuName = (TextView) findViewById(R.id.tv_ssk);
        tvLeft = (TextView) findViewById(R.id.tv_left);
        tvLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        initData();
    }

    private void initData() {
        if (refactorBean != null) {
            RefactorBean.ResultsBean resultBean = refactorBean.getResults().get(refactorPos);
            double similarity = resultBean.getSimilarity();
            BigDecimal bigDecimal = new BigDecimal(similarity);
            similarity = bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            tvSim.setText(String.valueOf(similarity));
            tvName.setText(resultBean.getName());
            tvKuName.setText(PreferencesUtils.getInstance().getSharePreStr(PreferencesUtils.KU_ID_NAME));
            String personId = resultBean.getPerson_id();
            if (!TextUtils.isEmpty(personId)) {
                tvIdCardNo.setText(personId);
            }
            String head1Url = CommonUtils.StringToBase64(CommonUtils.trimPhotoAtdefault(refactorBean.getFace_image_uri())).replaceAll("\n", "");
            //head1Url = head1Url.replaceAll("\n", "");
            String head2Url = CommonUtils.StringToBase64(CommonUtils.trimPhotoAtdefault(resultBean.getFace_image_uri())).replaceAll("\n", "");
            //head2Url = head2Url.replaceAll("\n", "");
            String picture1Url = CommonUtils.StringToBase64(CommonUtils.trimPhotoAtdefault(refactorBean.getPicture_uri())).replaceAll("\n", "");
            //picture1Url = picture1Url.replaceAll("\n", "");
            String picture2Url = CommonUtils.StringToBase64(CommonUtils.trimPhotoAtdefault(resultBean.getPicture_uri())).replaceAll("\n", "");
            //picture2Url = picture2Url.replaceAll("\n", "");
            simpleDraweeViewhead1.setImageURI(PreferencesUtils.getInstance().getSharePreStrBaseUrl(PreferencesUtils.BASE_URL) + String.format(ReqUrls.URL_GET_PHOTO2, PreferencesUtils.getInstance().getSharePreStrClusterId(PreferencesUtils.CLUSTER_ID), head1Url));
            simpleDraweeViewhead2.setImageURI(PreferencesUtils.getInstance().getSharePreStrBaseUrl(PreferencesUtils.BASE_URL) + String.format(ReqUrls.URL_GET_PHOTO2, PreferencesUtils.getInstance().getSharePreStrClusterId(PreferencesUtils.CLUSTER_ID), head2Url));
            simpleDraweeViewCjz1.setImageURI(PreferencesUtils.getInstance().getSharePreStrBaseUrl(PreferencesUtils.BASE_URL) + String.format(ReqUrls.URL_GET_PHOTO2, PreferencesUtils.getInstance().getSharePreStrClusterId(PreferencesUtils.CLUSTER_ID), picture1Url));
            simpleDraweeViewCjz2.setImageURI(PreferencesUtils.getInstance().getSharePreStrBaseUrl(PreferencesUtils.BASE_URL) + String.format(ReqUrls.URL_GET_PHOTO2, PreferencesUtils.getInstance().getSharePreStrClusterId(PreferencesUtils.CLUSTER_ID), picture2Url));
            Log.i(TAG, "------" + PreferencesUtils.getInstance().getSharePreStrBaseUrl(PreferencesUtils.BASE_URL)
                    + String.format(ReqUrls.URL_GET_PHOTO2, PreferencesUtils.getInstance().getSharePreStrClusterId(PreferencesUtils.CLUSTER_ID), head1Url));
            Log.i(TAG, "------" + PreferencesUtils.getInstance().getSharePreStrBaseUrl(PreferencesUtils.BASE_URL)
                    + String.format(ReqUrls.URL_GET_PHOTO2, PreferencesUtils.getInstance().getSharePreStrClusterId(PreferencesUtils.CLUSTER_ID), head2Url));
            Log.i(TAG, "------" + PreferencesUtils.getInstance().getSharePreStrBaseUrl(PreferencesUtils.BASE_URL)
                    + String.format(ReqUrls.URL_GET_PHOTO2, PreferencesUtils.getInstance().getSharePreStrClusterId(PreferencesUtils.CLUSTER_ID), picture1Url));
            Log.i(TAG, "------" + PreferencesUtils.getInstance().getSharePreStrBaseUrl(PreferencesUtils.BASE_URL)
                    + String.format(ReqUrls.URL_GET_PHOTO2, PreferencesUtils.getInstance().getSharePreStrClusterId(PreferencesUtils.CLUSTER_ID), picture2Url));
        }
    }
}
